package cn.zktr.Personnel.model.service.zhouyongcong;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.zktr.Personnel.model.dao.ouyangpeng.RetWaltDao;
import cn.zktr.Personnel.model.dao.zhouxiong.CwaQLaeDAO;
import cn.zktr.Personnel.model.dao.zhouxiong.CwaQtsDAO;
import cn.zktr.Personnel.model.dao.zhouyongcong.*;
import cn.zktr.Personnel.model.pojos.*;

@Service
@Transactional(rollbackFor=Exception.class)
public class boolService {
	@Autowired 
	private PmsPotDao ppd;
	@Autowired
	private PmsActDao pad;
	@Autowired
	private PmsBzbDao pbd;
	@Autowired
	private RetWaltDao rwd;
	@Autowired
	private AuditTabDao atd;
	@Autowired
	private AuditZdDao azd;
	@Autowired
	private PmsLxfsDao pld;
	@Autowired
	private AuditMdyDao amd;
	@Autowired
	private AuditDao ad;
	@Autowired
	private PmsDisDao pdd2;
	@Autowired
	private PmsEmplxDao peld;
	@Autowired
	private PmsYQDao pyqd;
	@Autowired
	private PmsYGDao pygd;
	@Autowired
	private CwaQLaeDAO cqd;
	@Autowired
	private CwaQtsDAO qts;
	@Autowired
	private PmsHCesDao phcd;
	
	public int bool_HCes(){
		List<PerPmsHCes> list1 = (List<PerPmsHCes>) phcd.findAll();
		if(list1.size()==0) {
			return 0;
		}
		return list1.get(list1.size()-1).getCesid();
	}
	
	public int bool_Qts(){
		List<PerCwaQts> list1 = (List<PerCwaQts>) qts.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getQtsid();
	}
	
	public int bool_QLae(){
		List<PerCwaQLae> list1 = (List<PerCwaQLae>) cqd.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getLaeid();
	}
	
	public int bool_YG(){
		List<PerPmsYG> list1 = (List<PerPmsYG>) pygd.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getYgid();
	}
	
	public int bool_YQ(){
		List<PerPmsYQ> list1 = (List<PerPmsYQ>) pyqd.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getYqid();
	}
	
	public int bool_Lxfs(){
		List<PerPmsEmplx> list1 = (List<PerPmsEmplx>) peld.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getLxid();
	}
	
	public int bool_Emplx(){
		List<PerPmsEmplx> list1 = (List<PerPmsEmplx>) peld.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getLxid();
	}
	
	public int bool_Dis(){
		List<PerPmsDis> list1 = (List<PerPmsDis>) pdd2.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getDisid();
	}
	
	public int bool_Audit(){
		List<PerAudit> list1 = (List<PerAudit>) ad.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getAuditid();
	}
	
	public int bool_Mdy(){
		List<PerAuditMdy> list1 = (List<PerAuditMdy>) amd.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getMdyid()+1;
	}
	
	public int bool_Lxfs(String lxfs) {
		List<PerPmsLxfs> list = (List<PerPmsLxfs>) pld.findByLxfs(lxfs);
		if(list.size()!=0) {
			return list.get(0).getLxfsid();
		}else{
			List<PerPmsLxfs> list1 = (List<PerPmsLxfs>) pld.findAll();
			if(list1.size()==0) {
				return 1;
			}
			return list1.get(list1.size()-1).getLxfsid()+1;
		}
	}
	
	public int bool_Act(String acc,String pwd) {
		for(PerPmsAct ppa : pad.findAll()) {
			if(ppa.getActaccount().equals(acc)) {
				if(ppa.getActpwd().equals(pwd)) {
					return ppa.getActid();
				}else {
					return -1;
				}
			}
		}
		return -1;
	}
	public int bool_Act(PerPmsEmp ppe,String pwd) {
		PerPmsAct ppa = ppe.getPerPmsActs().get(0);
		if(ppa.getActpwd().equals(pwd)) {
			return ppa.getActid();
		}else {
			return 0;
		}
	}
	
	public int bool_Zd(String ztname,PerAuditTab pat) {
		List<PerAuditZd> list = (List<PerAuditZd>) azd.findByZtname(ztname);
		if(list.size()!=0) {
			for(PerAuditZd paz : list) {
				if(paz.getPerAuditTab().getTabid()==pat.getTabid()) {
					return list.get(0).getZtid();
				}
			}
		}
		List<PerAuditZd> list1 = (List<PerAuditZd>) azd.findAll();
		if(list1.size()==0) {
			return 1;
		}
		return list1.get(list1.size()-1).getZtid()+1;
	}
	public int bool_Tab(String tabname) {
		List<PerAuditTab> list = (List<PerAuditTab>) atd.findByTabname(tabname);
		if(list.size()!=0) {
			return list.get(0).getTabid();
		}else{
			List<PerAuditTab> list1 = (List<PerAuditTab>) atd.findAll();
			if(list1.size()==0) {
				return 1;
			}
			return list1.get(list1.size()-1).getTabid()+1;
		}
	}
	public int bool_Pot(String potzw) {
		List<PerPmsPot> list = (List<PerPmsPot>) ppd.findByPotzw(potzw);
		if(list.size()!=0) {
			return list.get(0).getPotid();
		}else{
			List<PerPmsPot> list1 = (List<PerPmsPot>) ppd.findAll();
			return list1.get(list1.size()-1).getPotid()+1;
		}
	}
	public int bool_Bzb(int dept,int pot) {
		List<PerPmsBzb> list = (List<PerPmsBzb>) pbd.findAll();
		for(PerPmsBzb ppb : list) {
			if(ppb.getPerPmsDept().getDeptid()==dept && ppb.getPerPmsPot().getPotid()==pot) {
				return ppb.getBzbiid();
			}
		}
		return list.get(list.size()-1).getBzbiid()+1;
	}
	public int bool_Walt() {
		List<PerRetWAlt> list = (List<PerRetWAlt>) rwd.findAll();
		if(list.size()==0) {
			return 0 ;
		}
		return list.get(list.size()-1).getAltid()+1;
	}
}
